
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({

    state: {
        num: 100
    },
    mutations: {
        addNum(state, val = 1) {
            state.num += val
        },
        subNum(state, val = 1) {
            state.num -= val
        },
        setNum(state, val) {
            state.num = val
        },
    },
    actions: {
        asyncAddNum(store, val = 1) {
            setTimeout(() => {
                store.commit('addNum', val)
            }, 2000);
        },
        asyncSubNum(store, val = 1) {
            setTimeout(() => {
                store.commit('subNum', val)
            }, 2000);
        }
    }
})
export default store